package com.cy.pj.sys.service.Impl;

import com.cy.pj.sys.common.exception.ServiceException;
import com.cy.pj.sys.dao.BlogTypeDao;
import com.cy.pj.sys.pojo.BlogType;
import com.cy.pj.sys.service.BlogTypeService;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 */

@Service
@Transactional(readOnly = true)//只读
public class BlogTypeServiceImpl implements BlogTypeService {
    @Autowired
    private BlogTypeDao blogTypeDao;
    @Override
    public List<BlogType> selectBlogs(BlogType blogType) {
        List<BlogType> list= blogTypeDao.selectBlogs(blogType);
        if (list == null ){
            throw new ServiceException("记录不存在");
        }
        return list;
    }

    @Override
    public int insertBlog(BlogType blogType) {
        int rows= blogTypeDao.insertBlog(blogType);
        return rows;
    }

    @Override
    public BlogType selectById(Long id) {
        BlogType blogType= blogTypeDao.selectById(id);
        if (blogType==null)
            throw new ServiceException("记录不存在1");
        return blogType;
    }

    @Override
    public int updateBlog(BlogType blogType) {
            int rows = blogTypeDao.updateBlog(blogType);
            if (rows==0)
                throw new ServiceException("记录不存在2");
            return rows;
    }

    @Override
    public Long deleteById(Long... id) {
        Long i = blogTypeDao.deleteById(id);
        return i;
    }
}
